﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

public partial class UserControls_ContactForm : System.Web.UI.UserControl
{

  private SmtpClient SMTP;
  private NetworkCredential NetCred;
  private string Email = "info@analyseinvestor.dk";

  protected void Page_Load(object sender, EventArgs e)
  {
    MultiView1.ActiveViewIndex = 0;
    //Setup SMTP
    SMTP = new SmtpClient("asmtp.unoeuro.com");
    SMTP.Port = 587;
    SMTP.EnableSsl = true;

    //Setup credentials
    NetCred = new NetworkCredential(Email, "Aktie123");

    //Security
    SMTP.UseDefaultCredentials = true;
    SMTP.Credentials = NetCred;
  }
  protected void Button1_Click(object sender, EventArgs e) 
  {
    try
    {
      MailMessage msg = new MailMessage();
      msg.From = new MailAddress(EmailTextBox.Text);
      msg.To.Add("info@analyseinvestor.dk");
      msg.Subject = SubjectTextBox.Text;
      msg.Body = "Name: " + NameTextBox.Text + "<br /><br />Email: " + EmailTextBox.Text + "<br /><br />" + MessageTextBox.Text;
      msg.IsBodyHtml = true;
      SMTP.Send(msg);
      SMTP.Dispose();
      MultiView1.ActiveViewIndex = 1;
    }
    catch (SmtpException ex)
    {
      ErrorLabel.Text = ex.Message;
    }
  }
}